package freemind.controller;

import freemind.main.XMLElement;

public class XMLProtocolBase implements XMLProtocol{

	private int enegModulo,operacao,protocolo;
	private XMLElement xmlMap = null;
	
	public int getEnegModulo() {
		return this.enegModulo;
	}

	public int getOperacao() {
		return this.operacao;
	}
	
	public int getProtocolo(){
		return this.protocolo;
	}

	public XMLElement readXML(String s){	
		XMLElement readed = new XMLElement();
		readed.parseString(s);
		
		this.operacao = readed.getIntAttribute("operacao");
		this.protocolo = readed.getIntAttribute("protocolo");
		this.enegModulo = readed.getIntAttribute("eneg_modulo");		
		
		return readed;
	}
	
	public XMLElement getXML(){
		return this.getXML(new NodeAdapterBase());
	}
	
	public XMLElement getXML(NodeAdapterBase adapter){
		xmlMap = new XMLElement();
		
		xmlMap.setName("mindmap");
		
		xmlMap.addChild( adapter.createMapMetaXML() );
				
		xmlMap.setAttribute("operacao", this.operacao);
		xmlMap.setAttribute("protocolo", this.protocolo);
		xmlMap.setAttribute("eneg_modulo", this.enegModulo);			
		
		return xmlMap;
	}
	
	public XMLProtocol getResponse() {
		setOperacao(XMLProtocol.RESPONSE);
		
		return null;
	}

	public XMLProtocol makeRequest() {
		setOperacao(XMLProtocol.REQUEST);
		
		return null;
	}

	public void setEnegModulo(int enegModulo) {
		this.enegModulo = enegModulo;
	}

	public void setOperacao(int operacao) {
		this.operacao = operacao;
	}
	
	public void setProtocolo(int protocolo) {
		this.protocolo = protocolo;
	}	
	
	public XMLProtocolBase(int protocolo, int enegModulo){
		setProtocolo(protocolo);
		setEnegModulo(enegModulo);
	}

}
